//2009/09/04 19:11:10
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
#include <sstream>
#include <algorithm>

using namespace std;

class BadClock
{
public:
    double nextAgreement(string trueTime, string skewTime, int hourlyGain)
    {
		double realtime = 3600 * ((trueTime[0]-'0')*10 + trueTime[1]-'0') + 60.0 * ((trueTime[3]-'0')*10 + trueTime[4]) + (trueTime[6]-'0')*10 + (trueTime[7]-'0');
		double skewtime = 3600 * ((skewTime[0]-'0')*10 + skewTime[1]-'0') + 60.0 * ((skewTime[3]-'0')*10 + skewTime[4]) + (skewTime[6]-'0')*10 + (skewTime[7]-'0');
		double lead = realtime - skewtime;
		if(hourlyGain < 0) lead = -lead;
		if(lead < 0) lead += 12*60*60;
		return lead / abs(hourlyGain);
    }
};
